/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 *
 */

import { AbstractSyscapTransform } from '../abstract/abstract-syscap-transform.js';
import { TaskNames } from '../common/task-names.js';
import { TargetTaskService } from '../service/target-task-service.js';
import LegacyFATask = TaskNames.LegacyFATask;
import { ConfigJson } from '../../options/configure/config-json-options.js';
import ConfigOptObj = ConfigJson.ConfigOptObj;
import path from 'path';

import { CommonConst } from '../../const/common-const.js';
import { JsonProfile } from '../../model/json-profile.js';
import { resModelLoader } from '../../utils/loader/file/res-model-loader.js';

/**
 * Legacy Syscap Transform Task
 *
 * @since 2022/09/8
 */
export class LegacySyscapTransform extends AbstractSyscapTransform {
  private readonly jsonFilePath: string;

  constructor(taskService: TargetTaskService) {
    super(taskService, LegacyFATask.SYSCAP_TRANSFORM);
    this.jsonFilePath = path.resolve(this.sourceRoot, CommonConst.CONFIG_JSON);
  }

  protected getJsonProfileByModel(): JsonProfile {
    const jsonFile = resModelLoader.getConfigJson(this.jsonFilePath) as ConfigOptObj;
    return {
      jsonFilePath: this.jsonFilePath,
      profile: jsonFile,
      deviceTypes: jsonFile.module.deviceType,
      deviceConfig: CommonConst.DEVICE_TYPE,
      configurationProfile: CommonConst.CONFIG_JSON,
    };
  }
}
